<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新经资讯后台管理</title>
    <link rel="stylesheet" type="text/css" href="../../static/admin/css/reset.css">
    <link rel="stylesheet" type="text/css" href="../../static/admin/css/main.css">
    <script type="text/javascript" src="../../static/admin/js/jquery-1.12.4.min.js"></script>
    <script src="../../static/admin/tinymce/js/tinymce/tinymce.min.js"></script>
    <script src="../../static/admin/js/news_review_detail.js"></script>
</head>
<body>
<div class="breadcrub">
    当前位置：新闻管理>新闻审核
</div>
<div class="pannel">
    <form class="news_review">
        <h3 class="review_title">内容审核</h3>
        <div class="form_group">
            <label>新闻标题：</label>
            <input type="text" class="input_txt2" value="{{ data.news.title }}" readonly>
        </div>
        <div class="form_group">
            <label>新闻分类：</label>
            <div class="category_name">{{ data.news.category }}</div>
        </div>
        <div class="form_group">
            <label>新闻摘要：</label>
            <textarea class="input_multxt" readonly>{{ data.news.digest }}</textarea>
        </div>
        <div class="form_group">
            <label>索引图片：</label>
            <img src="" alt="{{ data.news.index_image_url }}" class="index_pic">
        </div>
        <div class="form_group">
            <label>新闻内容：</label>
            <div class="rich_wrap fl">
                <input class="input_area" id="rich_content" value="{{ data.news.content }}" name="content">
            </div>
        </div>
        <div class="form_group indent_group">
            <input type="radio" name="action" checked="" value="accept"> 通过&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="radio" name="action" value="reject"> 拒绝通过
        </div>
        <div class="form_group group_hide">
            <label>拒绝原因：</label>
            <textarea class="input_multxt" name="reason"></textarea>
        </div>
        <div class="form_group indent_group line_top">
            <input type="submit" value="确定" class="confirm">
            <input type="button" value="取消" class="cancel" onclick="cancel()">
        </div>
        <!-- 隐藏字段，用于记录当前新闻id -->
        <input name="news_id" value="{{ data.news.id }}" hidden>
    </form>
</div>

<script>
    $(function () {
        var $radio = $('input[name="action"]');
        $radio.click(function () {
            if ($(this).index() == 1) {
                $('.group_hide').show();
            }
            else {
                $('.group_hide').hide();
            }
        });

        tinymce.init({
            //选择class为content的标签作为编辑器
            selector: '#rich_content',
            //方向从左到右
            directionality: 'ltr',
            //语言选择中文
            language: 'zh_CN',
            //高度为400
            height: 400,
            width: '100%',
            //按tab不换行
            nonbreaking_force_tab: true,
            readonly: 1
        });
        $(".news_review").submit(function (e) {
            e.preventDefault();

            var params = {};
            // 获取到所有的参数
            $(this).serializeArray().map(function (x) {
                params[x.name] = x.value;
            });
            // 取到参数以便判断
            var action = params["action"];
            var news_id = params["news_id"];
            var reason = params["reason"];
            if (action == "reject" && !reason) {
                alert('请输入拒绝原因');
                return;
            }
            params = {
                "action": action,
                "news_id": news_id,
                "reason": reason
            }
            $.ajax({
                url: "/admin/news_review_detail",
                type: "post",
                contentType: "application/json",
                headers: {
                    "X-CSRFToken": getCookie("csrf_token")
                },
                data: JSON.stringify(params),
                success: function (resp) {
                    if (resp.errno == "0") {
                        // 返回上一页，刷新数据
                        location.href = document.referrer;
                    } else {
                        alert(resp.errmsg);
                    }
                }
            })
        })
    })
</script>
</body>
</html>